﻿using System;
using System.Windows.Input;
using BHS.TFSChangsetAnalyser.Export;

namespace BHS.TFSChangsetAnalyser.ViewModel
{
    public class CommandFactory
    {
        private readonly IExportFilenameProvider _exportFilenameProvider;
        private readonly IChangesetInfoExporter _changesetInfoExporter;
        private readonly IErrorPresenter _errorPresenter;

        public CommandFactory(IExportFilenameProvider exportFilenameProvider, 
                              IChangesetInfoExporter changesetInfoExporter,
                              IErrorPresenter errorPresenter)
        {
            _exportFilenameProvider = exportFilenameProvider;
            _changesetInfoExporter = changesetInfoExporter;
            _errorPresenter = errorPresenter;
        }

        public ICommand CreateCommand(Type commandType, IMainWindowViewModel viewModel)
        {
            if (commandType == typeof(AnalyseCommand))
            {
                return new AnalyseCommand(viewModel, _errorPresenter);
            }
            else if (commandType == typeof(ExportCommand))
            {
                return new ExportCommand(viewModel, _exportFilenameProvider, _changesetInfoExporter);
            }
            else if (commandType == typeof(SaveDefaultsCommand))
            {
                return new SaveDefaultsCommand(viewModel);
            }
            else
            {
                throw new NotImplementedException(string.Format("Command type: {0} is not supported by this factory", commandType.Name));
            }
        }
    }
}
